import java.util.Arrays;
import java.util.Scanner;

public class ArrayTest {

    public static void main(String[] args) {
        int[][] arr = new int[][]{{1,2,3,4},{5,6,7,8}};
    }
    public static void main6(String[] args) {
        // 注意：虽然省去了new T[], 但是编译器编译代码时还是会还原
        int[] arr = {1,2,3,4,5,6,7};
        //打印一个
        System.out.println(arr[0]);
        //全部打印
        //三种方法
        //第一种
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        for (int x: arr) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println(Arrays.toString(arr));
    }

    /**
     * 暴力求解得到数量超总数一半的数字
     * @param arr
     * @return
     */
    public static int halfMode(int[] arr){
        int ret = arr[0];
        int maxCount = 0;
        for (int i = 0; i < arr.length; i++) {
            int count = 0;
            for (int j = 0; j < arr.length; j++) {
                if(arr[j] == arr[i]){
                    count++;
                }
            }
            if(count > maxCount){
                maxCount = count;
                ret = arr[i];
            }
        }
        return ret;
    }

    /**
     * 投票法得到数量超总数一半的数字
     * @param arr
     * @return
     */
    public static int halfMode2(int[] arr){
        int ret = arr[0];
        int count = 1;
        for (int i = 1; i < arr.length; i++) {
            if(arr[ret] == arr[i]){
                count++;
            }else{
                count--;
            }
            if(count == 0){
                ret = arr[i + 1];
            }
        }
        return ret;
    }

    /**
     * 排序得到数量超总数一半的数字
     * @param arr
     * @return
     */
    public static int halfMode1(int[] arr){
        Arrays.sort(arr);
        return arr[arr.length / 2];
    }

    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int[] nums = new int[num];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }
        System.out.println(halfMode(nums));
    }
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int[] nums = new int[num];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }
        boolean flag = false;
        if(flag = count(nums)){
            System.out.println(flag);
        }else {
            System.out.println(flag);
        }
    }
    public static boolean count(int[] arr) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] % 2 == 1){
                count++;
            }else{
                count = 0;
            }
            if(count == 3){
                return true;
            }
        }
        return false;
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int[] nums = new int[num];
        int ans = 0;
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
            ans ^= nums[i];
        }
        System.out.println(ans);
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int[] nums = new int[num];
        int target = 0;
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }
        target =  scanner.nextInt();
        for (int i = 0; i < nums.length; i++) {
            int j = 0;
            for (j = 0; j < nums.length; j++) {
                if(i == j){
                    continue;
                }
                if(nums[i] + nums[j] == target){
                    System.out.println("[" + i + "," + j + "]");
                    break;
                }
            }
            if(j < nums.length){
                break;
            }
        }
    }
    public static void main1(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i + 1;
        }
        /*transform(arr);
        printArray(arr);
        System.out.println();
        System.out.println(avg(arr));

        System.out.println(Arrays.toString(arr));
        System.out.println(binarySearch(arr,7));
        System.out.println(binarySearch(arr,12));*/

    }

    public static int binarySearch(int[] arr,int goal){
        int left = 0;
        int right = arr.length - 1;
        while(left <= right){
            int mid = (left + right) >>> 1;
            if(goal > arr[mid]){
                left = mid + 1;
            }else if(goal < arr[mid]){
                right = mid - 1;
            }else{
                return mid;
            }
        }
        return -1;
    }

    public static void adjustOrder(int[] arr){
        int left = 0;
        int temp = 0;
        int right = arr.length - 1;
        while (true){
            while(arr[left] % 2 == 1 && left < right) left++;
            while(arr[right] % 2 == 0 && left < right) right--;
            if(left >= right){
                break;
            }
            temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
            left++;
            right--;
        }
    }

    public static double avg(int[] arr){
        int sum = 0;
        for (int x: arr) {
            sum += x;
        }
        return sum * 1.0 / arr.length;
    }

    public static void transform(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] *= 2;
        }
    }

    public static void printArray(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
